package com.xxxx;

import com.xxxx.dao.OrderDao;
import com.xxxx.dao.UserDao;
import com.xxxx.service.BookService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created By ShaoXikai on 2022/7/18
 */
public class TestForName {

    @Test
    public void testId() {
        // 获取IoC容器
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 获取bean对象
        // BookDao bookDao = ac.getBean("bookDao", BookDao.class);
        // bookDao.save();
        BookService bookService = ac.getBean("bookService", BookService.class);
        bookService.save();
    }

    @Test
    public void testForName() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService service2 = context.getBean("service2", BookService.class);
        service2.save();
    }

    // 静态工程
    @Test
    public void testFactory() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        OrderDao orderDao = ac.getBean("orderDao", OrderDao.class);
        orderDao.save();
    }

    // 实例化工厂
    @Test
    public void testUserDao() {
        ApplicationContext application = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao = application.getBean("userDao", UserDao.class);
        UserDao userDao2 = application.getBean("userDao", UserDao.class);
        System.out.println(userDao2);
        System.out.println(userDao);
        System.out.println("TestForName.testUserDao");
        // userDao.Save();
    }


}
